package main

import (
	"fmt"
	"time"
)

func main() {
	timeAdd()
	//printSplit(50)
	beforeOneDay()
	calculatorDiffer()
}

func FormatStamp(stamp int64) string {
	return time.Unix(stamp, 0).Format("2006-01-02 15:04:05")
}

func timeAdd() {
	now := time.Now()
	// 10分钟前
	duration, _ := time.ParseDuration("-10m")
	m1 := now.Add(duration)
	timeFormatStr := FormatStamp(m1.Unix())
	fmt.Println("10分钟前:", timeFormatStr)
	fmt.Println("时间间隔为：", duration)
	fmt.Println("时间间隔为小时：", duration.Hours())
	fmt.Println("时间间隔为分钟：", duration.Minutes())
	fmt.Println("时间间隔为秒：", duration.Seconds())

	fmt.Println("since用法：", time.Since(now)) //过去了多少毫秒：打印-> since用法： 15.0051ms
}

//疑问：时间这里如何传值？
//func timeSinceTest(nowT Time) {
//	fmt.Println(time.Since(nowT))
//}

func beforeOneDay() {
	// 一天前
	d, _ := time.ParseDuration("-24h")
	now := time.Now()
	d1 := now.Add(d)
	timeFormatStr := FormatStamp(d1.Unix())
	fmt.Println("一天前:", timeFormatStr)
}

func afterOneDay() {
	now := time.Now()
	// 一天后
	dd, _ := time.ParseDuration("24h")
	dd1 := now.Add(dd)
	timeFormatStr := FormatStamp(dd1.Unix())
	fmt.Println("一天后:", timeFormatStr)
}

func calculatorDiffer() {
	now := time.Now()

	// 10分钟前
	m, _ := time.ParseDuration("-10m")
	m1 := now.Add(m)

	// Sub 计算两个时间差
	subM := now.Sub(m1)
	fmt.Println(subM.Minutes(), "分钟")
}
